<template>
  <div class="layout">
    <!-- 侧边栏 -->
    <el-menu
        :default-active="route.path"
        class="sidebar"
        router
        background-color="#f0f8ff"
        text-color="#333"
        active-text-color="#ff8c00"
    >
      <!-- 教师栏目 -->
      <template v-if="userStore.userInfo === 'teacher'">
<!--       显示 头像和姓名 -->
        <el-menu-item class="student-menu-item" v-if="userStore.userDetails">
          <el-avatar size="medium" :src="userStore.userDetails.avatar" />
          <span class="student-name">{{ userStore.userDetails.userName }}</span>
        </el-menu-item>
        <el-menu-item index="/home/statistic">
         控制台
        </el-menu-item>
        <el-menu-item index="/home/student-management">
          学生管理
        </el-menu-item>
        <el-menu-item index="/home/view-projects">
          查看项目
        </el-menu-item>
        <el-menu-item index="/home/review-join-project">
          审核加入项目
        </el-menu-item>
        <el-menu-item index="/home/review-create-project">
          审核创建项目
        </el-menu-item>
        <el-menu-item index="/home/account-management">
          账号管理
        </el-menu-item>
<!--        退出登录 -->
        <el-menu-item  @click="userStore.logout" >
          退出登录
        </el-menu-item>

      </template>

      <!-- 学生栏目 -->
      <template v-else-if="userStore.userInfo === 'student'">
        <el-menu-item class="student-menu-item" v-if="userStore.userDetails">
          <el-avatar size="medium" :src="userStore.userDetails.avatar" />
          <span class="student-name" v-if="!userStore.userDetails.userName">学生</span>
          <span class="student-name" v-else>{{ userStore.userDetails.userName  }}</span>
        </el-menu-item>
        <el-menu-item index="/home/view-projects">
          查看项目
        </el-menu-item>
        <el-menu-item index="/home/apply-project">
          申报项目
        </el-menu-item>


        <!-- 项目管理展开项 -->
        <el-sub-menu index="project-management" popper-class="submenu">
          <template #title>项目管理</template>
          <el-menu-item index="/home/project-management/pending-application">
            申请审核中
          </el-menu-item>
          <el-menu-item index="/home/project-management/pending-review">
            项目审核中
          </el-menu-item>
          <el-menu-item index="/home/project-management/rejected">
            加入驳回
          </el-menu-item>
          <el-menu-item index="/home/project-management/approved">
           创建驳回
          </el-menu-item>
          <el-menu-item index="/home/project-management/ongoing">
            进行中
          </el-menu-item>
          <el-menu-item index="/home/project-management/created">
            已创建
          </el-menu-item>

        </el-sub-menu>
        <el-menu-item index="/home/UpdateMyInfo">
          更新个人信息
        </el-menu-item>
        <!--        退出登录 -->
        <el-menu-item  @click="userStore.logout" >
          退出登录
        </el-menu-item>
      </template>
    </el-menu>

    <!-- 主内容区域 -->
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script setup>
import { useUserStore } from '@/stores/user.js'
import { useRoute } from 'vue-router'

const userStore = useUserStore()
const route = useRoute()
</script>

<style scoped>
.layout {
  display: flex;
  background-color: #f9f9f9;
}
.sidebar {
  width: 220px;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  padding-top: 20px;
  background-color: #cbe3f8; /* 浅蓝背景 */
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
}

.el-menu-item,
.el-sub-menu__title {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  display: flex;
  justify-content: center; /* 居中文字 */
  padding: 10px 0;
  margin-top: 15px;
}

.el-menu-item:hover,
.el-sub-menu__title:hover {
  color: #ff8c00; /* 橙色悬停效果 */
}

.el-menu-item.is-active {
  background-color: #f6eecb; /* 高亮项背景色 */
  color: #ff8c00;
}

.content {
  flex: 1;
  padding: 30px;
  padding-left: 240px; /* 留出侧边栏宽度 */
  background-color: #fff;
  min-height: 100vh;
}

.submenu .el-menu-item {
  padding-left: 30px;
}
.student-menu-item {
  display: flex;
  align-items: center;
  padding: 10px 15px; /* 添加内边距 */
  transition: background-color 0.3s; /* 添加过渡效果 */
}

.student-menu-item:hover {
  background-color: #f5f5f5; /* 悬停时背景颜色 */
}

.student-name {
  margin-left: 10px; /* 左边距 */
  font-weight: 600; /* 加粗字体 */
  color: #333; /* 字体颜色 */
}
</style>
